package com.example.core.creational.factoryMethod;

/**
 * @author li_xilei
 */
public class SendFactory {

    /**
     * 普通工厂
     * @param type
     * @return
     */
    public Sender produce(String type) {
        if ("mail".equals(type)) {
            return new MailSender();
        } else if ("sms".equals(type)) {
            return new SmsSender();
        } else {
            System.out.println("请输入正确的类型!");
            return null;
        }
    }

    /**
     * 静态工厂
     * @return
     */
    public static Sender produceMail(){
        return new MailSender();
    }

    public static Sender produceSms(){
        return new SmsSender();
    }

    public static void main(String[] args) {
        SendFactory factory = new SendFactory();
        Sender sender = factory.produce("sms");
        Sender sender2 = SendFactory.produceMail();
        sender.send();
        sender2.send();
    }
}
